<?php

class Cluster {
    function Cluster() {
    }
    public function execute() {
    	global $page;
    	$page->success = true;
    	$page->root = $this->getClusterList($page);
    }
    
    public function getClusterList($page) {
    	$where = "";
    	if($_REQUEST[cluster]) {
    		$where.= "and (clusternum like '{$_REQUEST[cluster]}%' or clustername like '%{$_REQUEST[cluster]}%' ) ";
    	}
    	$sql = "select * from td_view_fav where 1=1 {$where} order by favorable desc limit {$_REQUEST[start]},{$_REQUEST[limit]}";
    	$sqlC = "select count(*) cou from td_view_fav where 1=1";
    	$rs = DB::GetQueryResult($sql,false,0);
    	$cou = DB::GetQueryResult($sqlC,true,0);
    	$page->totalProperty = $cou[cou];
    	$arr = array();
    	$i=0;
    	foreach($rs as $x) {
    		$tem = array(
    			'id'=>$x[id],
    			'clusterNum'=>$x[clusternum],
    			'clusterName' =>$x[clustername],
    			'favorable'=>$x[favorable],
    			'isInCluster'=>$x[is_in_cluster],
    			'isService'=>$x[is_service],
    			'updateTime'=>$x[update_time]
    		);
    		$arr[$i++] = $tem;
    	}
    	return $arr;
    	
    }

      public function updateFiled() {
    	global $page;
    	$field = $_POST['fieldName'];
    	$newValue = $_POST['value'];
    	$id = $_POST['id'];
    	$sql = "update td_cluster_favorable set `{$field}` = '{$newValue}' where id ={$id} ";
    	if(DB::Query($sql)) {
    		$page->success = true ;
    	} else {
    		$page->success = false ;
    	}
    }
}
?>